<?php

namespace App\Http\Controllers\CallingCards\RMS;

use App\Http\Controllers\BaseController;
use App\Service\CallingCards\UsersStoriesLogService;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class StoryController extends BaseController
{

    /**
     * 微信加盟小程序-文章数据看板
     * @param Request $request
     * @return JsonResponse
     */
    public function lists(Request $request): JsonResponse
    {
        $startTime = (string)$request->get('startTime', '');
        $endTime   = (string)$request->get('endTime', '');
        $type      = (int)$request->get('type', 0);
        $pageNum   = (int)$request->get('pageNum', 1);
        $pageSize  = (int)$request->get('pageSize', 20);

        if (!$startTime) {
            $startTime = strtotime(date('Y-m-d'));
        } else {
            $startTime = strtotime($startTime);
        }
        if (!$endTime) {
            $endTime = strtotime(date('Y-m-d 23:59:59'));
        } else {
            $endTime = strtotime($endTime . ' 23:59:59');
        }

        return $this->success(UsersStoriesLogService::getList($startTime, $endTime, $type, $pageNum, $pageSize));
    }

    /**
     * 微信加盟小程序-文章数据看板
     * @param Request $request
     * @return JsonResponse
     */
    public function getReadArticleUses(Request $request): JsonResponse
    {
        $storiesId = (int)$request->get('articleId', 0);
        $startTime = (string)$request->get('startTime', '');
        $endTime   = (string)$request->get('endTime', '');
        $pageNum   = (int)$request->get('pageNum', 1);
        $pageSize  = (int)$request->get('pageSize', 20);

        if (!$startTime) {
            $startTime = strtotime(date('Y-m-d'));
        } else {
            $startTime = strtotime($startTime);
        }
        if (!$endTime) {
            $endTime = strtotime(date('Y-m-d 23:59:59'));
        } else {
            $endTime = strtotime($endTime . ' 23:59:59');
        }

        return $this->success(UsersStoriesLogService::getReadArticleUses($storiesId, $startTime, $endTime, $pageNum, $pageSize));
    }

}
